﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace ProjManagSolution
{
    public partial class EditMilestone : ChildWindow
    {
        protected Milestone curMS = new Milestone();
        
        public EditMilestone(Milestone ms)
        {
            InitializeComponent();

            curMS = ms;

            ShowMileStoneInfo();
        }

        protected void ShowMileStoneInfo()
        {
            txtboxMilestoneName.Text = curMS.Name;
            txtboxDescription.Text = curMS.Description;
            datepickStartDate.SelectedDate = curMS.StartDate;
            datepickEndDate.SelectedDate = curMS.EndDate;
        }

        protected bool Input_Validate()
        {
            if (txtboxMilestoneName.Text == "")
            {
                MessageBox.Show("Milestone name cannot be null!");
                return false;
            }
            else if (this.datepickStartDate.SelectedDate.HasValue == false)
            {
                MessageBox.Show("Start Date and End Date cannot be null!");
                datepickStartDate.SelectedDate = curMS.StartDate;
                return false;
            }
            else if (this.datepickEndDate.SelectedDate.HasValue == false)
            {
                MessageBox.Show("Start Date and End Date cannot be null!");
                datepickEndDate.SelectedDate = curMS.EndDate;
                return false;
            }   
            else if (this.datepickStartDate.SelectedDate < DateTime.Now.Date && this.datepickStartDate.SelectedDate != curMS.StartDate.Date)
            {
                MessageBox.Show("Start Date cannot be set ealier than today!");
                datepickEndDate.SelectedDate = curMS.EndDate;
                datepickStartDate.SelectedDate = curMS.StartDate;
                return false;
            }
            else if (this.datepickStartDate.SelectedDate > this.datepickEndDate.SelectedDate)
            {
                MessageBox.Show("Start date must be ealier than end date!");
                datepickEndDate.SelectedDate = curMS.EndDate;
                return false;
            }

            return true;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if(Input_Validate())
                this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

